package com.java2104.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.java2104.entity.DeliveryAddress;
import com.java2104.mapper.DeliveryAddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Service
public class DeliveryAddressService implements IService<DeliveryAddress> {

    @Autowired
    private DeliveryAddressMapper deliveryAddressMapper;

    @Override
    public BaseMapper<DeliveryAddress> getBaseMapper() {
        return deliveryAddressMapper;
    }

    public List<DeliveryAddress> list(String phoneNumber, String addressee){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(phoneNumber!=null && !"".equals(phoneNumber.trim())){
            queryWrapper.like("phone_number",phoneNumber);
        }
        if(addressee!=null && !"".equals(addressee.trim())){
            queryWrapper.like("addressee",addressee);
        }
        return list(queryWrapper);
    }

    public boolean updateAddress(DeliveryAddress deliveryAddress){
        return updateById(deliveryAddress);
    }

    public int saveAddress(DeliveryAddress deliveryAddress){
        return deliveryAddressMapper.insert(deliveryAddress);
    }

    /*public boolean deleteAddress(Integer id){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.set("delete_status",1);
        updateWrapper.eq("id",id);
        return update(updateWrapper);
    }*/



    @Override
    public boolean saveBatch(Collection<DeliveryAddress> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<DeliveryAddress> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<DeliveryAddress> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(DeliveryAddress entity) {
        return false;
    }

    @Override
    public DeliveryAddress getOne(Wrapper<DeliveryAddress> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<DeliveryAddress> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<DeliveryAddress> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public Class<DeliveryAddress> getEntityClass() {
        return null;
    }
}
